, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2017.png")
data <- mapdata %>%
mutate(year_num = as.numeric(as.character(Signed_Year)),
signed = ifelse(year_num < 2019, 1, 0),
signed = ifelse(is.na(signed), 0, signed),
signed = as.factor(signed))
ggplot(data = data$geometry) +
#geom_sf(aes(fill = mapdata$china), size = 0.02) +
geom_sf(aes(fill = data$signed), size = 0.02) +
#scale_fill_discrete(name = "Year BRI \n entry") +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
scale_fill_viridis_d() +
labs(fill = "Signed",
title = "2018") +
theme_void() +
theme(legend.position = "bottom"
, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2018.png")
data <- mapdata %>%
mutate(year_num = as.numeric(as.character(Signed_Year)),
signed = ifelse(year_num < 2020, 1, 0),
signed = ifelse(is.na(signed), 0, signed),
signed = as.factor(signed))
ggplot(data = data$geometry) +
#geom_sf(aes(fill = mapdata$china), size = 0.02) +
geom_sf(aes(fill = data$signed), size = 0.02) +
#scale_fill_discrete(name = "Year BRI \n entry") +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
scale_fill_viridis_d() +
labs(fill = "Signed",
title = "2019") +
theme_void() +
theme(legend.position = "bottom"
, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2019.png")
data <- mapdata %>%
mutate(year_num = as.numeric(as.character(Signed_Year)),
signed = ifelse(year_num < 2021, 1, 0),
signed = ifelse(is.na(signed), 0, signed),
signed = as.factor(signed))
ggplot(data = data$geometry) +
#geom_sf(aes(fill = mapdata$china), size = 0.02) +
geom_sf(aes(fill = data$signed), size = 0.02) +
#scale_fill_discrete(name = "Year BRI \n entry") +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
scale_fill_viridis_d() +
labs(fill = "Signed",
title = "2020") +
theme_void() +
theme(legend.position = "bottom"
, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2020.png")
data <- mapdata %>%
mutate(year_num = as.numeric(as.character(Signed_Year)),
signed = ifelse(year_num < 2022, 1, 0),
signed = ifelse(is.na(signed), 0, signed),
signed = as.factor(signed))
ggplot(data = data$geometry) +
#geom_sf(aes(fill = mapdata$china), size = 0.02) +
geom_sf(aes(fill = data$signed), size = 0.02) +
#scale_fill_discrete(name = "Year BRI \n entry") +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
scale_fill_viridis_d() +
labs(fill = "Signed",
title = "2021") +
theme_void() +
theme(legend.position = "bottom"
, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2021.png")
data <- mapdata %>%
mutate(year_num = as.numeric(as.character(Signed_Year)),
signed = ifelse(year_num < 2023, 1, 0),
signed = ifelse(is.na(signed), 0, signed),
signed = as.factor(signed))
ggplot(data = data$geometry) +
#geom_sf(aes(fill = mapdata$china), size = 0.02) +
geom_sf(aes(fill = data$signed), size = 0.02) +
#scale_fill_discrete(name = "Year BRI \n entry") +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
scale_fill_viridis_d() +
labs(fill = "Signed",
title = "2022") +
theme_void() +
theme(legend.position = "bottom"
, panel.background = element_rect(fill = "aliceblue")
, plot.title = element_text(face = "bold")
, legend.key.width = unit(1, "cm")
, legend.key.size = unit(.5, "cm")
)
#ggsave("./figures/2022.png")
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
knitr::opts_chunk$set(echo = TRUE)
# Load packages
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
# Load data
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
# The function takes the network_base data calculates the 5 percentile distance
# and compares the distance of each country to the 5th percentile. If it is  above it drops the country
id_function <- function(country, year) {
network_base %>%
filter(year %in% seq(t_year-10:t_year)) %>%
group_by(ctry1, ctry2) %>%
summarize(mean_dist = mean(IdealPointDistance)) %>%
drop_na() %>%
group_by(ctry1) %>%
# Here we vary the cut-off point
# Top 5th percentile
mutate(quantile_10 = quantile(mean_dist, 0.05)) %>%
filter(mean_dist < quantile_10)
}
c <- network_base %>% filter(treated_country == 1) %>%
select(ctry1, year) %>%
filter(year == 2013) %>%
distinct()
countries <- c$ctry1
t_year <- unique(c$year)
# Container
datalist = list()
# For loop for data with ID
for (i in countries) {
# ... make some data
dat <- id_function(i)
#dat$i <- i  # maybe you want to keep track of which iteration produced it?
datalist[[i]] <- dat # add it to your list
}
data <- bind_rows(datalist) %>% distinct()
data_saved <- data
# Here we vary the 0.25 threshold
data <- data %>% filter(mean_dist < 0.25)
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('../analysis/graphs/network/distribution-of-distances.pdf')
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('./replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
test <- knitr::kable(data %>% filter(ctry1 == 'Hungary'),
caption = "Table 1: Most proximate countries to Hungary",
col.names = c("Country 1", " Country 2", "Average Distance", "Fifth percentile"),
booktabs = TRUE,
format = "latex") %>%
kable_styling(font_size = 8)
knitr::opts_chunk$set(echo = TRUE)
# Load packages
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
# Load data
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
# The function takes the network_base data calculates the 5 percentile distance
# and compares the distance of each country to the 5th percentile. If it is  above it drops the country
id_function <- function(country, year) {
network_base %>%
filter(year %in% seq(t_year-10:t_year)) %>%
group_by(ctry1, ctry2) %>%
summarize(mean_dist = mean(IdealPointDistance)) %>%
drop_na() %>%
group_by(ctry1) %>%
# Here we vary the cut-off point
# Top 5th percentile
mutate(quantile_10 = quantile(mean_dist, 0.05)) %>%
filter(mean_dist < quantile_10)
}
c <- network_base %>% filter(treated_country == 1) %>%
select(ctry1, year) %>%
filter(year == 2013) %>%
distinct()
countries <- c$ctry1
t_year <- unique(c$year)
# Container
datalist = list()
# For loop for data with ID
for (i in countries) {
# ... make some data
dat <- id_function(i)
#dat$i <- i  # maybe you want to keep track of which iteration produced it?
datalist[[i]] <- dat # add it to your list
}
data <- bind_rows(datalist) %>% distinct()
data_saved <- data
# Here we vary the 0.25 threshold
data <- data %>% filter(mean_dist < 0.25)
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
test <- knitr::kable(data %>% filter(ctry1 == 'Hungary'),
caption = "Table 1: Most proximate countries to Hungary",
col.names = c("Country 1", " Country 2", "Average Distance", "Fifth percentile"),
booktabs = TRUE,
format = "latex") %>%
kable_styling(font_size = 8)
cluster_data <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
V(network_full)$frame.color <- "white"
knitr::opts_chunk$set(echo = TRUE)
# Load packages
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
# Load data
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
# The function takes the network_base data calculates the 5 percentile distance
# and compares the distance of each country to the 5th percentile. If it is  above it drops the country
id_function <- function(country, year) {
network_base %>%
filter(year %in% seq(t_year-10:t_year)) %>%
group_by(ctry1, ctry2) %>%
summarize(mean_dist = mean(IdealPointDistance)) %>%
drop_na() %>%
group_by(ctry1) %>%
# Here we vary the cut-off point
# Top 5th percentile
mutate(quantile_10 = quantile(mean_dist, 0.05)) %>%
filter(mean_dist < quantile_10)
}
c <- network_base %>% filter(treated_country == 1) %>%
select(ctry1, year) %>%
filter(year == 2013) %>%
distinct()
countries <- c$ctry1
t_year <- unique(c$year)
# Container
datalist = list()
# For loop for data with ID
for (i in countries) {
# ... make some data
dat <- id_function(i)
#dat$i <- i  # maybe you want to keep track of which iteration produced it?
datalist[[i]] <- dat # add it to your list
}
data <- bind_rows(datalist) %>% distinct()
data_saved <- data
# Here we vary the 0.25 threshold
data <- data %>% filter(mean_dist < 0.25)
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
test <- knitr::kable(data %>% filter(ctry1 == 'Hungary'),
caption = "Table 1: Most proximate countries to Hungary",
col.names = c("Country 1", " Country 2", "Average Distance", "Fifth percentile"),
booktabs = TRUE,
format = "latex") %>%
kable_styling(font_size = 8)
# Relocate variables first to have connected entities
data <- data %>% select(-quantile_10) %>% relocate(ctry1, ctry2, everything())
# Create the network object
network_full <- graph_from_data_frame(d = data, directed = F)
# Calculate the clusters
#cluster_full <- cluster_optimal(network_full, weights = NULL)
cluster_full <- network_full  %>% cluster_walktrap()
# Storing the cluster information in a dataframe
# We will use this later to specify the clusters across the years
cluster_data <- as_tibble(cbind(cluster_full$names, cluster_full$membership)) %>%
arrange(V2) %>%
rename('ctry1' = 'V1',
'cluster' = 'V2') %>%
mutate(cluster = as.numeric(cluster))
degree <- degree(network_full)
number_of_ties <- enframe(degree) %>%
unnest
# Here we vary the the minimum number of ties
cluster_data <- left_join(cluster_data, number_of_ties,
by = c('ctry1' = 'name')) %>%
filter(value > 3)
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
#write_csv2(cluster_data, 'C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
cluster_data <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
V(network_full)$frame.color <- "white"
E(network_full)$arrow.mode <- 0
# Create the network figure
#pdf('../analysis/graphs/network/full-network.pdf')
plot.igraph(network_full,  vertex.color=membership(cluster_full), vertex.size = 7, vertex.label.cex=0.45)
#dev.off()
knitr::kable(
list(cluster_data[1:31,], cluster_data[32:61,]),
caption = 'Comminuty Membership I',
col.names = c("Country", 'Cluster', 'Ties'),
booktabs = TRUE,
"latex") %>%
kable_styling(font_size = 8)
knitr::kable(
list(cluster_data[62:93,], cluster_data[94:125,]),
caption = 'Comminuty Membership II',
col.names = c("Country", 'Cluster', 'Ties'),
booktabs = TRUE) %>%
kable_styling(font_size = 8)
knitr::opts_chunk$set(echo = TRUE)
# Load packages
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
# Load data
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
# The function takes the network_base data calculates the 5 percentile distance
# and compares the distance of each country to the 5th percentile. If it is  above it drops the country
id_function <- function(country, year) {
network_base %>%
filter(year %in% seq(t_year-10:t_year)) %>%
group_by(ctry1, ctry2) %>%
summarize(mean_dist = mean(IdealPointDistance)) %>%
drop_na() %>%
group_by(ctry1) %>%
# Here we vary the cut-off point
# Top 5th percentile
mutate(quantile_10 = quantile(mean_dist, 0.05)) %>%
filter(mean_dist < quantile_10)
}
c <- network_base %>% filter(treated_country == 1) %>%
select(ctry1, year) %>%
filter(year == 2013) %>%
distinct()
countries <- c$ctry1
t_year <- unique(c$year)
# Container
datalist = list()
# For loop for data with ID
for (i in countries) {
# ... make some data
dat <- id_function(i)
#dat$i <- i  # maybe you want to keep track of which iteration produced it?
datalist[[i]] <- dat # add it to your list
}
data <- bind_rows(datalist) %>% distinct()
data_saved <- data
# Here we vary the 0.25 threshold
data <- data %>% filter(mean_dist < 0.25)
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
test <- knitr::kable(data %>% filter(ctry1 == 'Hungary'),
caption = "Table 1: Most proximate countries to Hungary",
col.names = c("Country 1", " Country 2", "Average Distance", "Fifth percentile"),
booktabs = TRUE,
format = "latex") %>%
kable_styling(font_size = 8)
# Relocate variables first to have connected entities
data <- data %>% select(-quantile_10) %>% relocate(ctry1, ctry2, everything())
# Create the network object
network_full <- graph_from_data_frame(d = data, directed = F)
# Calculate the clusters
#cluster_full <- cluster_optimal(network_full, weights = NULL)
cluster_full <- network_full  %>% cluster_walktrap()
# Storing the cluster information in a dataframe
# We will use this later to specify the clusters across the years
cluster_data <- as_tibble(cbind(cluster_full$names, cluster_full$membership)) %>%
arrange(V2) %>%
rename('ctry1' = 'V1',
'cluster' = 'V2') %>%
mutate(cluster = as.numeric(cluster))
degree <- degree(network_full)
number_of_ties <- enframe(degree) %>%
unnest
# Here we vary the the minimum number of ties
cluster_data <- left_join(cluster_data, number_of_ties,
by = c('ctry1' = 'name')) %>%
filter(value > 3)
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
#write_csv2(cluster_data, 'C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
cluster_data <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
V(network_full)$frame.color <- "white"
E(network_full)$arrow.mode <- 0
#### Reproduces Figure 4 in the Manuscript (note that the plot may look slightly different as the same network can be arranged in many different ways, however, the voting communities remain the same irrespective of the configuration of the network) ####
# Create the network figure
#pdf('C:\Users\CSteinert\OneDrive - Universität St.Gallen\Dokumente\unga_bri_project\replication_files\analysis\analysis\graphs\network\full-network.pdf')
plot.igraph(network_full,  vertex.color=membership(cluster_full), vertex.size = 7, vertex.label.cex=0.45)
#dev.off()
#knitr::include_graphics('C:\Users\CSteinert\OneDrive - Universität St.Gallen\Dokumente\unga_bri_project\replication_files\analysis\analysis\graphs\network\full-network.pdf')
V(network_full)$frame.color <- "white"
E(network_full)$arrow.mode <- 0
#### Reproduces Figure 4 in the Manuscript (note that the plot may look slightly different as the same network can be arranged in many different ways, however, the voting communities remain the same irrespective of the configuration of the network) ####
# Create the network figure
#pdf('C:\Users\CSteinert\OneDrive - Universität St.Gallen\Dokumente\unga_bri_project\replication_files\analysis\analysis\graphs\network\full-network.pdf')
plot.igraph(network_full,  vertex.color=membership(cluster_full), vertex.size = 7, vertex.label.cex=0.75)
#dev.off()
knitr::opts_chunk$set(echo = TRUE)
# Load packages
library(tidyverse)
library(broom)
library(kableExtra)
library(igraph)
# Load data
network_base <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/network_base.csv')
# The function takes the network_base data calculates the 5 percentile distance
# and compares the distance of each country to the 5th percentile. If it is  above it drops the country
id_function <- function(country, year) {
network_base %>%
filter(year %in% seq(t_year-10:t_year)) %>%
group_by(ctry1, ctry2) %>%
summarize(mean_dist = mean(IdealPointDistance)) %>%
drop_na() %>%
group_by(ctry1) %>%
# Here we vary the cut-off point
# Top 5th percentile
mutate(quantile_10 = quantile(mean_dist, 0.05)) %>%
filter(mean_dist < quantile_10)
}
c <- network_base %>% filter(treated_country == 1) %>%
select(ctry1, year) %>%
filter(year == 2013) %>%
distinct()
countries <- c$ctry1
t_year <- unique(c$year)
# Container
datalist = list()
# For loop for data with ID
for (i in countries) {
# ... make some data
dat <- id_function(i)
#dat$i <- i  # maybe you want to keep track of which iteration produced it?
datalist[[i]] <- dat # add it to your list
}
data <- bind_rows(datalist) %>% distinct()
data_saved <- data
# Here we vary the 0.25 threshold
data <- data %>% filter(mean_dist < 0.25)
ggplot(data, aes(mean_dist)) +
geom_histogram(bins = 50, color = 'black', fill = 'gray80') +
theme_minimal() +
labs(x = 'Average Distance',
y = 'Count')
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
test <- knitr::kable(data %>% filter(ctry1 == 'Hungary'),
caption = "Table 1: Most proximate countries to Hungary",
col.names = c("Country 1", " Country 2", "Average Distance", "Fifth percentile"),
booktabs = TRUE,
format = "latex") %>%
kable_styling(font_size = 8)
# Relocate variables first to have connected entities
data <- data %>% select(-quantile_10) %>% relocate(ctry1, ctry2, everything())
# Create the network object
network_full <- graph_from_data_frame(d = data, directed = F)
# Calculate the clusters
#cluster_full <- cluster_optimal(network_full, weights = NULL)
cluster_full <- network_full  %>% cluster_walktrap()
# Storing the cluster information in a dataframe
# We will use this later to specify the clusters across the years
cluster_data <- as_tibble(cbind(cluster_full$names, cluster_full$membership)) %>%
arrange(V2) %>%
rename('ctry1' = 'V1',
'cluster' = 'V2') %>%
mutate(cluster = as.numeric(cluster))
degree <- degree(network_full)
number_of_ties <- enframe(degree) %>%
unnest
# Here we vary the the minimum number of ties
cluster_data <- left_join(cluster_data, number_of_ties,
by = c('ctry1' = 'name')) %>%
filter(value > 3)
ggsave('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/analysis/analysis/graphs/network/distribution-of-distances.pdf')
#write_csv2(cluster_data, 'C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
cluster_data <- read_csv2('C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/cluster.csv')
# Create the voting network figure
V(network_full)$frame.color <- "white"
E(network_full)$arrow.mode <- 0
#### Reproduces Figure 4 in the Manuscript (note that the plot may look slightly different as the same network can be arranged in many different ways, however, the voting communities remain the same irrespective of the configuration of the network) ####
# Create the network figure
#pdf('C:\Users\CSteinert\OneDrive - Universität St.Gallen\Dokumente\unga_bri_project\replication_files\analysis\analysis\graphs\network\full-network.pdf')
plot.igraph(network_full,  vertex.color=membership(cluster_full), vertex.size = 7, vertex.label.cex=0.45)
#dev.off()
#knitr::include_graphics('C:\Users\CSteinert\OneDrive - Universität St.Gallen\Dokumente\unga_bri_project\replication_files\analysis\analysis\graphs\network\full-network.pdf')
#end
